var t = require("../common.js"), a = getApp(), e = "";

Page({
    behaviors: [ t ],
    data: {
        tabsIndex: 1,
        page: 1,
        isLoadMore: !0,
        total_page: 0,
        listData: [],
        networkLoading: !1,
        sort_order_field: "",
        sort_order_by: ""
    },
    onLoad: function(t) {
        t.status && this.setData({
            tabsIndex: t.status
        }), e = "", this.getGoodsList();
    },
    setTabsIndex: function(t) {
        var a = t.currentTarget.dataset.index;
        this.setData({
            tabsIndex: a
        }), this.getGoodsList();
    },
    confirmSearch: function(t) {
        console.log(t), t.detail.value != e && (e = t.detail.value, this.getGoodsList());
    },
    setSort: function(t) {
        this.setData({
            sort_order_field: t.detail.order_field,
            sort_order_by: t.detail.order_by
        }), this.getGoodsList();
    },
    gotoUserDe: function(t) {
        var a = t.currentTarget.dataset.item;
        wx.navigateTo({
            url: "/packageF/timeAppointment/AppointmentUserDe/AppointmentUserDe?id=" + a.id
        });
    },
    initData: function() {
        this.setData({
            page: 1,
            total_page: 0,
            isLoadMore: !0,
            listData: [],
            networkLoading: !1
        });
    },
    getGoodsList: function() {
        var t = this;
        this.initData();
        var s = a.getNetAddresss("plugin.reserve-simple.frontend.goods.search-goods"), o = {};
        1 == this.data.tabsIndex ? ("" != this.data.sort_order_field && (o.order_field = this.data.sort_order_field), 
        "" != this.data.sort_order_by && (o.order_by = this.data.sort_order_by), e && (o["search[keyword]"] = e)) : 2 == this.data.tabsIndex && (s = a.getNetAddresss("plugin.reserve-simple.frontend.obj.search-objs"), 
        e && (o.keyword = e)), a._getNetWork({
            url: s,
            data: o,
            success: function(e) {
                var s = e.data;
                if (1 != s.result) return a.tips(s.msg);
                console.log(s), t.data.total_page = s.data.last_page, t.data.total_page || (t.data.total_page = 0), 
                t.setData({
                    listData: s.data.data,
                    networkLoading: !0
                });
            }
        });
    },
    _getMoreData: function() {
        var t = this;
        if (this.data.isLoadMore = !1, !(this.data.page >= this.data.total_page)) {
            this.data.page += 1;
            var s = {
                page: this.data.page
            }, o = a.getNetAddresss("plugin.reserve-simple.frontend.goods.search-goods");
            1 == this.data.tabsIndex ? ("" != this.data.sort_order_field && (s.order_field = this.data.sort_order_field), 
            "" != this.data.sort_order_by && (s.order_by = this.data.sort_order_by), e && (s["search[keyword]"] = e)) : 2 == this.data.tabsIndex && (o = a.getNetAddresss("plugin.reserve-simple.frontend.obj.search-objs"), 
            e && (s.keyword = e)), a._postNetWork({
                url: o,
                data: s,
                success: function(a) {
                    var e = a.data;
                    if (t.data.isLoadMore = !0, 1 === e.result) {
                        var s = t.data.listData.concat(e.data.data);
                        t.setData({
                            listData: s
                        });
                    } else t.data.page = t.data.page - 1, t.data.isLoadMore = !1;
                }
            });
        }
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {
        this.data.isLoadMore ? this._getMoreData() : console.log("没有更多数据");
    },
    onShareAppMessage: function() {}
});